package com.lt.lumentracks.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@Configuration
@ConditionalOnWebApplication   // ← 只有 Web 环境才生效
@ConditionalOnClass(name = "jakarta.websocket.server.ServerContainer")
public class WebSocketConfig {

    // 创建ServerEndpointExporter对象，这个Bean会自动注册使用了@ServerEndpoint注解的类
    @Bean
    @ConditionalOnMissingBean   // 防止重复
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }
}